package com.sunkyc.controller.datascopedemo;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sunkyc.commons.annotation.ReqLog;
import com.sunkyc.commons.entity.R;
import com.sunkyc.commons.entity.TablePageData;
import com.sunkyc.commons.entity.PageQueryVo;
import com.sunkyc.module.book.entity.SunkycBook;
import com.sunkyc.module.book.service.SunkycBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
@RequiredArgsConstructor
@Api(tags = "权限测试")
public class BookController {

    private final SunkycBookService baseService;


    @GetMapping("/list")
    @ApiOperation("案例-图书信息分页查询")
    @SaCheckPermission("auth-book-query")
    @ReqLog
    public R<TablePageData<SunkycBook>> queryList(PageQueryVo pageQueryVo, SunkycBook sunkycBook) {
        return R.ok(baseService.queryList(pageQueryVo,sunkycBook));
    }


    @PostMapping()
    @ApiOperation("案例-添加图书信息")
    @SaCheckPermission("auth-book-add")
    @ReqLog
    public R<Void> addBook(@RequestBody @Validated SunkycBook sunkycBook) {
        return R.result(baseService.addBook(sunkycBook));
    }

    @PutMapping
    @ApiOperation("案例-修改图书信息")
    @SaCheckPermission("auth-book-update")
    @ReqLog
    public R<Void> updateBook(@RequestBody @Validated SunkycBook sunkycBook) {
        return R.result(baseService.updateBook(sunkycBook));
    }


    @DeleteMapping("/{ids}")
    @ApiOperation("案例-删除图书信息")
    @ReqLog
    @SaCheckPermission("auth-book-delete")
    public R<Void> delBook(@PathVariable("ids") Long[] ids) {
        return R.result(baseService.delBook(ids));
    }


}
